function die() {
  set +x
  echo "[ERROR] $*"
  exit 1
}

function set_gitee_hosts() {
    echo "ignore set gitee hosts."
}

function prepare_software() {
  apt-get update
  apt-get install -y vim wget git cmake gcc python3 python3-pip jq
  pip config set global.index-url https://mirrors.huaweicloud.com/repository/pypi/simple
}

function prepare_npm_soft() {
  apt-get install -y npm
}

function prepare_bingo() {
  cd ~
  git clone https://gitcode.com/openUBMC/bingo.git
  cd bingo
  sh install_local.sh
  bingo -v > /dev/null 2>&1 ||:
}

function prepare_git() {
  git_username=$1
  git_token=$2

  export GCM_CREDENTIAL_STORE=cache
  git config --global credential.helper manager
  git-credential-manager configure
  echo -e "protocol=https\nhost=gitcode.com\nusername=${git_username}\npassword=${git_token}" | git-credential-manager store
}

function prepare_conan() {
  conan_username=$1
  conan_password=$2
  conan remote add openubmc_dev https://devrepo.devcloud.cn-north-4.huaweicloud.com/artgalaxy/api/conan/cn-north-4_ad268a13b93c480087c8a1e4b0fe8b15_conan_1/
  conan user "${conan_username}" -p="${conan_password}" -r=openubmc_dev
  conan config set general.revisions_enabled=1
  conan remote list
}

function prepare_conan2() {
  conan_username=$1
  conan_password=$2
  conan profile detect --force
  conan remote remove conancenter
  conan remote add openubmc_dev https://devrepo.devcloud.cn-north-4.huaweicloud.com/artgalaxy/api/conan/cn-north-4_ad268a13b93c480087c8a1e4b0fe8b15_conan_1/ --insecure --force
  conan remote login openubmc_dev "${conan_username}" -p="${conan_password}"
  conan remote list
}

function prepare_sdk() {
  cd ~
  git clone https://gitcode.com/openUBMC/manifest.git
  cd ~/manifest
  bingo -v || true
  bingo build -t install_sdk || true
}

function prepare_apt() {
  mkdir -p /usr/share/keyrings
  gpg --keyserver keyserver.ubuntu.com --recv-keys BF3B2D407FDEDEA0DC91CC9412640FBCB175287A
  gpg --export BF3B2D407FDEDEA0DC91CC9412640FBCB175287A | sudo tee /usr/share/keyrings/openubmc.gpg >/dev/null
  echo "deb [arch=amd64 signed-by=/usr/share/keyrings/openubmc.gpg] https://openubmc-apt-repo.obs.cn-north-4.myhuaweicloud.com/Ubuntu/ noble main" | sudo tee /etc/apt/sources.list.d/openubmc.list
  apt update
}

function prepare_conan_cache() {
  cd ~
  echo "准备conan缓存"
  wget --no-check-certificate --show-progress=off https://192.168.0.13:8080/conan_cache/conan_cache.tar.gz &&
  tar -xzf  conan_cache.tar.gz -C ~ &&
  rm conan_cache.tar.gz
}